/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.suspend.b.b;

import android.content.Context;
import android.text.TextUtils;
import com.qihoo.gamecenter.sdk.suspend.b.b.b.a;
import com.qihoo.gamecenter.sdk.suspend.b.e.i;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.cert.X509Certificate;
import java.util.List;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.params.HttpClientParams;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;

public class c {
    private a b = com.qihoo.gamecenter.sdk.suspend.b.b.b.b.a();
    TrustManager[] a = { new X509TrustManager() {
        public void checkClientTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) {}

        public void checkServerTrusted(X509Certificate[] paramArrayOfX509Certificate, String paramString) {}

        public X509Certificate[] getAcceptedIssuers() {
            return null;
        }
    } };

    public HttpResponse a(Context paramContext, List paramList, String paramString1, String paramString2) {
        HttpClient localHttpClient = b(paramString1);
        HttpParams localHttpParams = localHttpClient.getParams();
        HttpHost localHttpHost = b.c(paramContext);
        if (localHttpHost != null)
            localHttpParams.setParameter("http.route.default-proxy", localHttpHost);
        HttpConnectionParams.setConnectionTimeout(localHttpParams, 15000);
        HttpConnectionParams.setSoTimeout(localHttpParams, 15000);
        HttpClientParams.setRedirecting(localHttpParams, false);
        HttpPost localHttpPost = new HttpPost(a(paramString1));
        localHttpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
        localHttpPost.setHeader("Charset", "UTF-8");
        if (!(TextUtils.isEmpty(paramString2)))
            localHttpPost.setHeader("Cookie", paramString2);
        localHttpPost
                .setHeader("User-Agent",
                        "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4");
        if (paramList != null) {
            UrlEncodedFormEntity localUrlEncodedFormEntity = new UrlEncodedFormEntity(paramList, "utf-8");
            localHttpPost.setEntity(localUrlEncodedFormEntity);
        }
        return localHttpClient.execute(localHttpPost);
    }

    public HttpResponse a(Context paramContext, String paramString1, String paramString2) {
        DefaultHttpClient localDefaultHttpClient = new DefaultHttpClient();
        HttpParams localHttpParams = localDefaultHttpClient.getParams();
        HttpHost localHttpHost = b.c(paramContext);
        if (localHttpHost != null)
            localHttpParams.setParameter("http.route.default-proxy", localHttpHost);
        HttpConnectionParams.setConnectionTimeout(localHttpParams, 15000);
        HttpConnectionParams.setSoTimeout(localHttpParams, 15000);
        HttpClientParams.setRedirecting(localHttpParams, false);
        HttpGet localHttpGet = new HttpGet(i.a(paramString1));
        localHttpGet.setHeader("Content-Type", "application/x-www-form-urlencoded");
        localHttpGet.setHeader("Charset", "UTF-8");
        if (!(TextUtils.isEmpty(paramString2)))
            localHttpGet.setHeader("Cookie", paramString2);
        localHttpGet
                .setHeader("User-Agent",
                        "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.125 Safari/533.4");
        return localDefaultHttpClient.execute(localHttpGet);
    }

    public static String a(String paramString) {
        paramString = paramString.replaceAll(" ", "%20");
        StringBuffer localStringBuffer = new StringBuffer();
        for (int i = 0; i < paramString.length(); ++i) {
            char c = paramString.charAt(i);
            byte[] arrayOfByte = String.valueOf(c).getBytes();
            if ((arrayOfByte == null) || (arrayOfByte.length <= 0))
                throw new UnsupportedEncodingException();
            if (arrayOfByte.length == 1) {
                localStringBuffer.append(c);
            }
            else {
                String str = new String(arrayOfByte);
                str = URLEncoder.encode(str, "UTF-8");
                localStringBuffer.append(str);
            }
        }
        return localStringBuffer.toString();
    }

    private HttpClient b(String paramString) {
        DefaultHttpClient localDefaultHttpClient = null;
        try {
            localDefaultHttpClient = new DefaultHttpClient();
        } catch (Exception localException) {
            localException.printStackTrace();
        }
        return localDefaultHttpClient;
    }
}